
#pragma once

#include "../Main.h"

#include "../StringHash.h"

class DragDropData;
class Widget;

enum DRAG_STATE
{
	DRAG_STATE_NONE,
	DRAG_STATE_MOUSEDOWN,
	DRAG_STATE_DRAGGING
};

typedef bool (*BeginDragDropCallback)( DragDropData* pxData, Widget* pxCaller );		// Called on widgets when a dragdrop operation begins (return false if cannot drag now)
typedef bool (*DragOverCallback)( const DragDropData* pxData, Widget* pxCaller );		// Called on widgets when dragging over them (return false if cannot drop) 
typedef void (*EndDragDropCallback)( const DragDropData* pxData, Widget* pxCaller );	// Called on widgets when dopping on them

class DragDropData
{
	friend class DragDropManager;

	public:

		DragDropData()
		{
			m_pxData = 0;
			Clear();
		};
		
		void SetID( const StringHash xID ) { m_xID = xID; }
		StringHash GetID() const { return m_xID; }

		void SetData( const void* pData, const u_int uDataSize )
		{
			if( !pData )
			{
				printf("crap, no data\n");
				return;
			}
			
			m_pxData = new char[uDataSize];
			memcpy( m_pxData, pData, uDataSize );
			m_uDataSize = uDataSize;
		}

		void GetData( const void* &pData, u_int &uDataSize ) const
		{
			pData = m_pxData;
			uDataSize = m_uDataSize;
		}

		void SetIcon( const StringHash xTextureHash )
		{
			m_xIcon = xTextureHash;
		}

	protected:

		void Clear()
		{
			m_xID = 0;
			delete static_cast<char*>(m_pxData);
			m_pxData = 0;
			m_uDataSize = 0;
			m_xIcon = GetStringHash( "DragDrop32" );
		}

	private:

		~DragDropData()
		{
			Clear();
		};

		StringHash m_xID;
		void* m_pxData;
		u_int m_uDataSize;
		StringHash m_xIcon;
};

class DragDropManager
{
	public:

		static void Initialise();
		static void Update();
		static void Render();
		static void Shutdown();

		static bool IsDragging();

	private:

		static DRAG_STATE s_eDragState;
		static u_int s_uDragOriginX;
		static u_int s_uDragOriginY;
		static Widget* s_pxWidgetOrigin;
		static DragDropData s_xDragDropData;

		DragDropManager()  {}
		~DragDropManager() {}
};

// eof
